<?php
/**
 * Created by PhpStorm.
 * User: yellow
 * Date: 2019/4/24
 * Time: 11:15
 */

namespace app\common\model;


use think\Model;

class Admin extends Model
{

    protected $insert = ['status' => 0];

    protected static function init(){
        //TODO:初始化内容
        self::observe(\app\common\event\Admin::class);
    }

    public function role(){
        return $this->hasOne("Role",'id','role_id')->bind(['role_name'=>'name']);
    }

    public function teams(){
        return $this->hasOne("site_team",'id','oid')->bind(['team_name'=>'name']);
    }

    public function site(){
        return $this->hasOne("site",'id','site_id')->bind(['site_name'=>'name']);
    }

    public function setIsAdminAttr($value){
        if ($value){
            return 1;
        } else{
            return 0;
        }
    }

    public function setStatusAttr($value){
        if ($value){
            return 1;
        } else{
            return 0;
        }
    }

    public function getCreateTimeAttr($value){
        return date('Y-m-d H:i', $value);
    }

}